package com.ibm.mall.action;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.ibm.mall.base.BaseAction;
import com.ibm.mall.model.CommodityClass;
import com.ibm.mall.model.PageBean;
import com.ibm.mall.util.QueryHelper;
/**
 * @author qiu
 * description:商品类别action层实现类
 */
@Controller
@Scope("prototype")
public class CommodityClassAction extends BaseAction<CommodityClass> {
	/**
	 * 
	 */
	private static final long serialVersionUID = -367260265995287606L;

	/*prototype begin*/
	
	private Map responseJson;
	
	private String commodityClassName;
	
	private int commodityClassId;

	/*prototype end*/
	
	
	/*function begin*/
	
	
	/**
	 * description:show the page
	 * @return String
	 */
	public String show(){
		return "show";
	}
	
	/**
	 * description:init table data
	 * @return String
	 */
	public String getData(){
		Map<String, Object> map = new HashMap<String, Object>();
        QueryHelper queryHelper=new QueryHelper(CommodityClass.class, "cc")//
			.addCondition("cc.status=?", (short)0)//查询出未被删除的
			.addOrderProperty("cc.id", true);
        //分页查询获得pageBean
        PageBean pageBean=commodityClassService.getPageBean(page,rows,queryHelper);
        map.put("rows", pageBean.getRecordList());
        map.put("total", pageBean.getRecordCount());
        this.setResponseJson(map);
        return "getData";
	}
	
	/**
	 * description:create a new commodity class
	 * @return String
	 */
	public String add(){
		SimpleDateFormat sf = new SimpleDateFormat();
		model.setInsertTime(sf.format(new Date()));
		model.setLastUpdateTime(sf.format(new Date()));
		model.setStatus((short)0);
		commodityClassService.saveCommodityClass(model);
		return "success";
	}
	
	public String delete(){
		Map<String, Object> map = new HashMap<String, Object>();
		CommodityClass commodityClass = commodityClassService.getCommdityClassById(commodityClassId);
		SimpleDateFormat sf = new SimpleDateFormat();
		commodityClass.setStatus((short)1);
		commodityClass.setLastUpdateTime(sf.format(new Date()));
		commodityClassService.deleteCommodityClass(commodityClass);
		map.put("result", true);
		this.setResponseJson(map);
		return "success";
	}
	
	public String modify(){
		Map<String, Object> map = new HashMap<String, Object>();
		CommodityClass commodityClass = commodityClassService.getCommdityClassById(model.getId());
		//if commodityClass
		SimpleDateFormat sf = new SimpleDateFormat();
		commodityClass.setCommodityClassName(model.getCommodityClassName());
		commodityClass.setLastUpdateTime(sf.format(new Date()));
		commodityClassService.updateCommodityClass(commodityClass);
		map.put("result", true);
		this.setResponseJson(map);
		return "success";
	}
	
	/*function end*/
	
	/*get/set function begin*/
	public Map getResponseJson() {
		return responseJson;
	}
	public void setResponseJson(Map responseJson) {
		this.responseJson = responseJson;
	}
	/*get/set function end*/

	public String getCommodityClassName() {
		return commodityClassName;
	}

	public void setCommodityClassName(String commodityClassName) {
		this.commodityClassName = commodityClassName;
	}

	public int getCommodityClassId() {
		return commodityClassId;
	}

	public void setCommodityClassId(int commodityClassId) {
		this.commodityClassId = commodityClassId;
	}


}
